// Package _0_最小的k个数 main
// @Title _0_最小的k个数
// @Description
// @Author  == 琳琳也叫王木木 ==  2022-01-13 9:12
// @Create  2022-01-13 9:12
package main

import "fmt"

func main() {
	fmt.Println(getLeastNumbers([]int{0, 1, 2, 1}, 1))
}

// 获取数组中最小的k个数
func getLeastNumbers(arr []int, k int) []int {
	if len(arr) == 0 {
		return nil
	}
	var ans []int
	for i := 0; i < len(arr); i++ {
		for e := i + 1; e < len(arr); e++ {
			if arr[i] > arr[e] {
				arr[i], arr[e] = arr[e], arr[i]
			}
		}
		if i < k {
			ans = append(ans, arr[i])
		}
	}
	return ans
}
